package edu.jhl;

import java.util.ArrayList;
import java.util.List;

 
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.View;

public class GameView extends View {
	public GameView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		this.setFocusable(true);
		this.setFocusableInTouchMode(true);
	}

	public GameView(Context context, AttributeSet attrs) {
		super(context, attrs);
		this.setFocusable(true);
		this.setFocusableInTouchMode(true);
	}

	public GameView(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
	}

	public void reset() {

	}

	public final int row = 10;
	public final int col = 10;
	public float width;
	public float height;
	public int selY;
	public int selX;
	public boolean isLine = false;
	public int grid[][] = new int[row][col];
	private Rect selRect = new Rect();
	public int lineType = 0;
	public final int V_LINE = 1;
	public final int H_LINE = 1;
	public final int ONE_C_LINE = 2;
	public final int TWO_C_LINE = 3;
	public int much = 0;

	public int[] imageType = new int[] { R.drawable.aa, R.drawable.bb,
			R.drawable.cc, R.drawable.dd, R.drawable.ee, R.drawable.ff,
			R.drawable.gg, R.drawable.hh, R.drawable.ii, R.drawable.jj,
			R.drawable.kk, R.drawable.ll, R.drawable.mm, R.drawable.nn,
			R.drawable.oo, R.drawable.pp };
	public Bitmap[] image;
	public List<Integer> type = new ArrayList<Integer>();

	public void fillImage(Context context) {
		int lth = imageType.length;
		image = new Bitmap[lth];
		for (int i = 0; i < lth; i++) {
			Bitmap bitmap = Bitmap.createBitmap((int) width, (int) height,
					Bitmap.Config.ARGB_8888);
			Drawable drw;
			Canvas canvas = new Canvas(bitmap);
			drw = context.getResources().getDrawable(imageType[i]);
			drw.setBounds(1, 1, 30, 30);
			drw.draw(canvas);
			image[i] = bitmap;
		}
	}

	public void initType() {
		int size = (row - 2) * (col - 2);
		int count = size / imageType.length;
		for (int j = 0; j < imageType.length; j++) {
			for (int i = 0; i < count; i++) {
				type.add(imageType[j]);
			}
		}
	}

	public void select(int x, int y) {
		invalidate(selRect);
		selX = Math.min(Math.max(x, 0), 9);
		selY = Math.min(Math.max(y, 0), 9);
		getrect(selX, selY, selRect);
		invalidate(selRect);

	}
	private void getrect(int x ,int y ,Rect rect){
		rect.set(((int)(x*width)), ((int)(y*height)), ((int)(x*width+width)), ((int)(y*height+height)));
	}
	protected void onDraw(Canvas canvas){
		Paint background=new Paint();
		background.setColor(Color.WHITE);
		canvas.drawRect(0, 0,getWidth(),getHeight(),background);
		Paint hilite = new Paint();
		hilite.setColor(getResources().getColor(R.color.hilite));
		Paint light= new Paint();
		light.setColor(getResources().getColor(R.color.light));
		for (int i = 0; i <=9; i++) {
			canvas.drawLine(0, i*height, getWidth(), i*height,light);
			canvas.drawLine(0, i*height+1, getWidth(), i*height+1, hilite);
			canvas.drawLine(i*width, 0,i*width, getHeight(), light);
			canvas.drawLine(i*width+1, 0, i*width+1, getHeight(), hilite);
		}
		if (CtrlView.) {
			
		}
		
	}
}
